from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# 连接数据库
engine = create_engine('mysql+pymysql://root:12111211@localhost:3306/scrapy_test?charset=utf8')
Session = sessionmaker(bind=engine)

class BaseModel():
    def __init__(self):
        self.session = Session()
    
    def add(self):
        self.session.add(self)
        self.session.commit()
        return self